package com.jeecms.wicool.dao.material.impl;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;
import com.jeecms.common.hibernate3.Finder;
import com.jeecms.common.hibernate3.HibernateBaseDao;
import com.jeecms.common.page.Pagination;
import com.jeecms.wicool.dao.material.WeixinMaterialDao;
import com.jeecms.wicool.dao.material.WeixinConfigurationDao;
import com.jeecms.wicool.entity.material.WeixinMaterial;
import com.jeecms.wicool.entity.material.WeixinConfiguration;

@Repository
public class WeixinConfigurationDaoImpl extends HibernateBaseDao<WeixinConfiguration, Integer>
		implements WeixinConfigurationDao {

	@Override
	protected Class<WeixinConfiguration> getEntityClass() {
		// TODO Auto-generated method stub
		return WeixinConfiguration.class;
	}
	@Override
	public Pagination getPage(Integer weixinMaterialId,Short configType,int pageNo, int pageSize) {
			Finder f = Finder.create("select bean from WeixinConfiguration bean where 1=1 ");
			if (weixinMaterialId!=null){
				f.append(" and bean.weixinMaterial.id = :weixinMaterialId");
				f.setParam("weixinMaterialId",weixinMaterialId);
			}
			if(configType!=null){
				f.append(" and bean.configType = :configType");
				f.setParam("configType",configType);
			}
			f.append(" order by bean.id desc");
			return find(f, pageNo, pageSize);
	}
	@Override
	public WeixinConfiguration findById(Integer id) {
		WeixinConfiguration  entity = get(id);
		return entity;
	}
	@Override
	public WeixinConfiguration save(WeixinConfiguration bean) {
		getSession().save(bean);
		return bean;
	}
	@Override
	public WeixinConfiguration deleteById(Integer id) {
		WeixinConfiguration entity = super.get(id);
		if (entity != null) {
			getSession().delete(entity);
		}
		return entity;
	}
	@Override
	public List<WeixinConfiguration> getListWeixinConfigurationByPId(Integer weixinMaterialId) {
		Finder f = Finder.create("select bean from WeixinConfiguration bean where bean.weixinMaterial.id = '"+ weixinMaterialId+"'");
		return find(f);
	}
	
}